package com.lsmw.management.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lsmw.management.entity.LsHotelInfo;
import com.lsmw.management.entity.LsRoom;
import com.lsmw.management.mapper.LsHotelInfoMapper;
import com.lsmw.management.service.LsHotelInfoService;
import com.lsmw.common_service.exceptionhandler.IdIllegalException;
import com.lsmw.commonutils.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 所有酒店基本信息 服务实现类
 * </p>
 *
 * @author 二号男嘉宾
 * @since 2020-12-02
 */
@Service
@Slf4j
public class LsHotelInfoServiceImpl extends ServiceImpl<LsHotelInfoMapper, LsHotelInfo> implements LsHotelInfoService {

//    @Resource
//    LsHotelInfoMapper lsHotelInfoMapper;

    @Override
    public R getHotelList() {
        log.info("查询了酒店");
        return R.ok().data("list", this.list());
    }

    @Override
    public R addHotel(LsHotelInfo lsHotelInfo) {
        log.info("添加了酒店");
        return this.save(lsHotelInfo) ? R.created() : R.invalidRequest();
    }

    @Override
    public R updateHotelById(String id, LsHotelInfo lsHotelInfo) {
        try {
            lsHotelInfo.setHotelId(Long.valueOf(id));
        } catch (Exception e) {
            throw new IdIllegalException(404, "修改酒店失败id有误，请检查id值或联系管理员");
        }
        log.info("修改了酒店");
        return this.updateById(lsHotelInfo) ? R.created() : R.notFound();
    }

    @Override
    public R removeHotelById(String id) {
        try {
            baseMapper.removeRoomByHotelId(new LambdaQueryWrapper<LsRoom>().eq(LsRoom::getHotelId, id));
            // lsHotelInfoMapper.removeRoomByHotelId(new LambdaQueryWrapper<LsRoom>().eq(LsRoom::getHotelId, id));
            return this.removeById(id) ? R.ok() : R.invalidRequest();
        } catch (Exception e) {
            return R.invalidRequest();
        }
    }
}
